/**
 * Created by mac on 14-5-29.
 */
var localData = {Rows:[
    {"shareId":"12345678","title":"麦兜自述","content":"我名叫做麦兜兜，我阿妈叫麦太太……我最喜欢吃麻油鸡，我最喜爱吃鸡屁屁，一起吃鸡一起来歌唱。",
       "image":"<a href='javascript:void(0);'>查看<a>","sharePhone":"13822222222", "createTime":"2014-5-20 13:14"}
]};
$(initGrid);
var grid = null;
function initGrid() {
    grid = $("#maingrid").ligerGrid({
        columns: [
            {display: '分享ID',name: 'shareId', width: '10%'},
            {display: '分享标题',name: 'title', width: '10%'},
            {display: '分享内容',name: 'content', width: '44%'},
            {display: '图片',name: 'image', width: '5%'},
            {display: '分享人手机号码',name: 'sharePhone', width: '10%'},
            {display: '创建时间',name: 'createTime', width: '10%'},
            {display: '操作', isSort: false, width: '9%',render: function(row, rowindex) {
                var h = "";
                h += '<a title="删除分享" href="javascript:delShare(' + row.id + ')">删除</a>';
                h += '<a title="查看该条分享评论" style="margin-left: 10px;" href="javascript:checkComment(' + row.id + ')">查看评论</a>';
                return h;
            }
        }],
        checkbox: true, enabledEdit: true,clickToEdit: false,selectRowButtonOnly: true,rownumbers:false,
        data:localData,
        //dataAction: 'server',
       // url: '@{system.SellerAccounts.getSellerAccountData()}',
        sortname: 'createdTime',usePager: 'true',pageSize: 50, width: '100%',height:'100%',
        onSelectRow: function(row, rowindex) {
            $("#txtrowindex").val(rowindex);
        },
        onAfterShowData: function(grid) {
            if ($.fn.ligerCheckBox) $(".l-grid-body input:checkbox,.l-grid-hd-cell input:checkbox", grid).ligerCheckBox({
                css: {
                    marginTop: 3
                }
            });
        }
    });
}

//删除学校
var delShare = function(rowid){
   $.ligerDialog.confirm('<span style="position:absolute;margin-top: 10px;">确认删除该条数据吗？</span>', function (yes) {
       //发送请求后台删除数据移除表格该条数据
       if(yes){
          //如果后台删除数据请求成功，则删除选中数据
          grid.deleteRow(0);
       }
   });
};

//批量删除学校
var delBatchShare = function(){
    //获取选中数据
    var rows = grid.getSelectedRows();
    if(rows.length < 1){
        parent.$.showShortMessage({msg:"请最少选择一条数据",animate:false});
        return false;
    }
    $.ligerDialog.confirm('<span style="position:absolute;margin-top: 10px;">确认删除这些数据吗？</span>', function (yes) {
       //发送请求后台删除数据移除表格该条数据
       if(yes){
           //如果后台删除数据请求成功，则删除选中数据
           grid.deleteSelectedRow();
       }
   });
};

//查看评论
var checkComment = function(shareId){
    var aaa = parent.contentWindow.$("#framecenter").attr("id");
    alert(aaa);return false;
    var tab = $("#framecenter").ligerGetTabManager();
    var url="share/comment/listComment.html";
    var tabId="commentManagement";
    var text = "评论";
    tab.removeTabItem(tabId);
    tab.addTabItem({ tabid : tabId,text: text, url: url });
};


